<template>
    <div>
        <!-- 票价管理-硬票调价 -->
        <el-row>
            <el-col :span="24">
                    <!-- 头部菜单栏 -->
                    <el-row>
                        <el-col :span="24" class="top-container">
                            <!-- 班次筛选栏 -->
                            <div class="left-choose lf">
                                <img src="../../assets/imgs/operation_bg_biaoti_default.png" alt="" class="lf"><div class="lf title">班次筛选</div>
                                <div style="height:10px"></div>
                                <br>
                                <div class="choose-title lf">班次日期</div>
                                <el-date-picker type="date" v-model="dateFrom" style="width: 130px;" size="mini" class="lf choose-input"></el-date-picker>
                                <div class="lf choose-title">&nbsp; 至&nbsp;</div>
                                <el-date-picker type="date" v-model="dateTo" style="width: 130px;" size="mini"></el-date-picker>
                                <img src="../../assets/imgs/operation_bg_sousuo_default.png" alt="" class="search-img" @click="timePopShow">
                                <div style="height:5px"></div>
                                <br>
                                <div class="choose-title lf">站点</div>
                                <!-- <el-input v-model="roadFrom" size="mini" style="width:150px" class="choose-input2"></el-input> -->
                                <el-autocomplete
                                  class="inline-input choose-input2"
                                  v-model="roadFrom"
                                  :fetch-suggestions="querySearch"
                                  placeholder="请输入内容"
                                  @select="handleSelect" size="mini" style="width:150px"
                                 ></el-autocomplete>
                                <div style="height:5px"></div>
                                <br>
                                <div class="lf choose-title">班次类型</div>
                                <DropDown :cv="chooseValue" :ci="chooseItem" :wt="banCiWt"></DropDown>
                            </div>
                            <!-- 调整方案 -->
                            <div class="right-choose lf">
                                <img src="../../assets/imgs/operation_bg_biaoti_default.png" alt="" class="lf"><div class="lf title">调整方案</div>
                                <div style="height:10px"></div>
                                <br>
                                <div class="choose-title lf">票型</div>
                                <el-select v-model="tickChoose" placeholder="" size="mini" class="choose-input lf" style="width:130px">
                                    <el-option
                                    v-for="item in tickType"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value">
                                    </el-option>
                                </el-select>
                                <div class="choose-title rf yuan">元</div>
                                <el-input v-model="price" size="mini" style="width:100px" class="choose-input2 rf"></el-input>
                                <el-select v-model="float" placeholder="" size="mini" class="choose-input rf" style="width:130px">
                                    <el-option
                                    v-for="item in numFloat"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value">
                                    </el-option>
                                </el-select>
                                <div style="height:30px"></div>
                                <br>
                                <div class="lf choose-title">标题</div>
                                <el-input type="textarea" v-model="textTitle" style="width:300px" class="choose-input lf"></el-input>
                            </div>
                            <button class="check-btn"><img src="../../assets/imgs/operation_btn_icon_quxiao_default.png" alt="" class="btn-img">取消</button>
                            <button class="check-btn btn2" @click="sendMod"><img src="../../assets/imgs/operation_btn_icon_tijiao_default.png" alt="" class="btn-img">提交修改</button>
                            <button class="check-btn btn3" @click="preview"><img src="../../assets/imgs/operation_btn_icon_shousuo_default.png" alt="" class="btn-img">预览</button>
                        </el-col>
                    </el-row>
                    <!-- 表格数据 -->
                    <div class="table-container">
                      <el-row>
                        <el-col :span="24">
                            <avue-crud :data="priceList[0].data" :option="priceList[0].option" @current-row-change="rowChange" class="price-table"></avue-crud>
                        </el-col>
                      </el-row>
                      <el-row>
                        <el-col :span="24" class="record-title">硬调记录</el-col>
                      </el-row>
                      <el-row>
                        <el-col :span="24">
                          <avue-crud :data="recordList.data" :option="recordList.option"></avue-crud>
                        </el-col>
                      </el-row>
                    </div>
            </el-col>
        </el-row>
        <!-- 弹窗 -->
        <div class="timer-pop" v-show="popTime">
            <div class="timer-title">请选择</div>
            <avue-crud :data="timePopList.data" :option="timePopList.option" @row-dblclick="handleRowDBLClick" class="time-table"></avue-crud>
            <button class="check-btn" @click="timeCancel"><img src="../../assets/imgs/operation_btn_icon_quxiao_default.png" alt="" class="btn-img">取消</button>
        </div>
    </div>
</template>

<script>
import DropDown from "../../components/common/dropdown";
import TableData from "../../components/common/tableData";
export default {
  data: function() {
    return {
      activeTag: "3-1",
      chooseValue: "buXian",
      banCiWt: { width: "100px" },
      chooseItem: [
        {
          value: "0",
          label: "所有"
        },
        {
          value: "1",
          label: "正常"
        },
        {
          value: "2",
          label: "加班"
        },
      ],
      dateFrom: "",
      dateTo: "",
      roadFrom: "",
      tickChoose: "",
      tickType: [],
      float: "numfloat",
      numFloat: [
        {
          value: "0",
          label: "数值浮动"
        },
        {
          value: "1",
          label: "比例浮动"
        },
        {
          value: "2",
          label: "固定值"
        }
      ],
      price: "",
      textTitle: "",
      priceList: [
        {
          page: {
            pageSizes: [10, 20, 30, 40],
            total: 2,
            currentPage: 1,
            pageSize: 10
          },
          data: [],
          option: {
            page: true,
            stripe: true,
            selection:true,
            menu: false,
            align: "center",
            menuAlign: "center",
            column: []
          }
        }
      ],
      listCheck: false,
      recordList:{
        data:[],
        option:{
          menu:false,
          column:[
            {
              label:"标题",
              prop:"remark"
            },
            {
              label:"班次日期",
              prop:"bus_date_end"
            },
            {
              label:"调整方案",
              prop:"adjust_type"
            },
            {
              label:"参数",
              prop:"adjust_para"
            },
            {
              label:"路线筛选",
              prop:"line_names"
            },
            {
              label:"站点筛选",
              prop:"st_id"
            },
            {
              label:"影响路线",
              prop:"line_count"
            },
            {
              label:"影响班次",
              prop:"bus_plan_count"
            },
            {
              label:"班次类型",
              prop:"bus_type"
            },
            {
              label:"票型筛选",
              prop:"price_types"
            },
            {
              label:"状态",
              prop:"status"
            },
          ]
        }
      },
      popTime:false,
      timePopList:{
        data:[],
        option:{
          menu:false,
          page:false,
          column:[
            {
              label:"名称",
              prop:"name"
            },
            {
              label:"起始时间",
              prop:"create_time"
            },
            {
              label:"结束时间",
              prop:"end_date"
            },
            {
              label:"备注",
              prop:"remark"
            },
          ]
        }
      },
      zhanDianList:[]
    };
  },
  methods: {
    preview() {
      this.$http
        .post(
          "/sch/bus/price/manage/previews?priceAdjust.bus_date_start="+this.dateFrom+"&priceAdjust.bus_date_end="+this.dateTo+"&priceAdjust.bus_type=1&priceAdjust.st_id="+this.roadFrom+"&priceAdjust.line_ids=158&priceAdjust.price_type_ids="+this.tickChoose+"&priceAdjust.adjust_type=0&priceAdjust.adjust_para="+this.float+"&priceAdjust.remark="+this.textTitle+"&priceAdjust.bus_plan_ids="
        )
        .then(data => {
          console.log(data);
          if (data.data[0] == -1) {
            this.$message.error(data.data[1]);
          } else {
            for (var item of data.data.list) {
              this.priceList[0].data.push({
                bus_date: item.bus_date,
                bus_id: item.bus_id,
                st_name: item.st_name,
                max_price: item.max_price,
                type_1_before: item.type_1_before,
                type_1_after: item.type_1_after,
                type_2_before: item.type_2_before
              });
            }
          }
        });
    },
    sendMod() {
      this.$http
        .post(
          "/sch/bus/price/manage/doCustomAdjust?priceAdjust.bus_date_start="+this.dateFrom+"&priceAdjust.bus_date_end="+this.dateTo+"&priceAdjust.bus_type=0&priceAdjust.st_id="+this.roadFrom+"&priceAdjust.line_ids=157&priceAdjust.price_type_ids="+this.tickChoose+"&priceAdjust.adjust_type=1&priceAdjust.adjust_para="+this.float+"&priceAdjust.remark="+this.textTitle+"&priceAdjust.bus_plan_ids="
        )
        .then(data => {
          console.log(data);
          if (data.data[0] == -1) {
            this.$message.error(data.data[1]);
          }
        });
    },
    tableCreate() {
      this.priceList[0].option.column.push(
        {
          label: "班次日期",
          prop: "bus_date"
        },
        {
          label: "班次号",
          prop: "bus_id"
        },
        {
          label: "站点名",
          prop: "st_name"
        },
        {
          label: "上限价",
          prop: "max_price"
        },
        {
          label: "全票",
          prop: "type_1_before"
        },
        {
          label: "调整后",
          prop: "type_1_after"
        },
        {
          label: "全票",
          prop: ""
        },
        {
          label: "学生票",
          prop: "type_2_before"
        },
        {
          label: "调整后",
          prop: "type_2_after"
        },
        {
          label: "老人价",
          prop: "old"
        },
        {
          label: "军残票",
          prop: "solider"
        },
        {
          label: "调整后",
          prop: "after"
        },
        {
          label: "双程票",
          prop: "double"
        },
      );
    },
    timePopShow(){
      this.popTime=true;
    },
    handleRowDBLClick(row,event){
      console.log(row);
      this.dateFrom=row.create_time;
      this.dateTo=row.end_date;
      this.popTime=false;
    },
    timeCancel(){
      this.popTime=false;
    },
    getTimePopList(){
      this.postRequest("/sys/customdatescope/list").then(data=>{
        this.timePopList.data=data.data.list
      })
    },
    querySearch(queryString, cb) {
        var restaurants = this.zhanDianList;
        var results = queryString ? restaurants.filter(this.createFilter(queryString)) : restaurants;
        // 调用 callback 返回建议列表的数据
        cb(results);
      },
      createFilter(queryString) {
        return (restaurant) => {
          return (restaurant.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0);
        }
      },
      getZhanDianList(){
        this.postRequest("/sch/data/station/listWithSpell").then(data=>{
          for(var item of data.data){
            this.zhanDianList.push({
              value:item.name,
              id:item.id
            })
          }
        })
      },
      gettickType(){
        this.postRequest("/tks/type/all").then(data=>{
          for(var item of data.data){
            this.tickType.push({
              label:item.name,
              value:item.id
            })
          }
        })
      },
      getrecordList(){
        this.postRequest("/sch/bus/price/manage/list").then(data=>{
          this.recordList.data=data.data.list;
        })
      },
    rowChange(val){
      
    }
  },
  computed: {},
  components: { DropDown, TableData },
  watch: {},
  mounted() {
    console.log("priceChange");
    this.$emit("sendActive", this.activeTag);
    this.tableCreate();
    this.getTimePopList();
    this.getZhanDianList();
    this.gettickType();
    this.getrecordList();
    this.$http
      .post(
        "/sch/bus/price/manage/previews?priceAdjust.bus_date_start=2018-08-22&priceAdjust.bus_date_end=2018-08-22&priceAdjust.bus_type=1&priceAdjust.st_id=245&priceAdjust.line_ids=158&priceAdjust.price_type_ids=1,2&priceAdjust.adjust_type=0&priceAdjust.adjust_para=1.00&priceAdjust.remark=&priceAdjust.bus_plan_ids="
      )
      .then(data => {
        console.log(data);
        for (var item of data.data) {
          this.priceList[0].data.push({
            bus_date: item.bus_date,
            bus_id: item.bus_id,
            st_name: item.st_name,
            max_price: item.max_price,
            type_1_before: item.type_1_before,
            type_1_after: item.type_1_after,
            type_2_before: item.type_2_before
          });
        }
      });
  }
};
</script>
<style scoped src="../../assets/css/service/priceChange.css">
</style>

